<?php


namespace App\Web\Controller;

use App\Command\ExportFile\DocxExportHelper;
use App\Command\ResumeParsing\FileToResume;
use App\Facades\UrlCrypt;
use App\Service\DbIndex;
use App\Service\FileHandler;
use App\Web\Model\CaseResume as CaseResumeModel;
use App\Web\Model\Customer;
use App\Web\Model\Manager;
use EchoPHP\Facades\Db;
use App\Web\Model\OperatorLog;
use EchoPHP\Facades\Log;
use EchoPHP\Http\Request;
use App\Web\Model\Resume as ResumeModel;
use App\Web\Model\MyResume as MyResumeModel;
use App\Customer\Model\ResumeRecommend;
use EchoPHP\Http\Response\JsonResponse;
use EchoPHP\Validator\Validator;
use Exception;

/**
 * 我的上传简历管理模块
 * @package App\Web\Controller
 */
class MyResume extends Controller {

    private $showFieldsDict = [
        'cname' => '姓名',
        'phone' => '联系方式',
        'salary' => '目前薪资',
        'expectsalary' => '期望薪资',
        'company' => '最近公司',
        'attach' => '简历附件',
    ];

    /**
     * 获取任务列表
     * @param Request $request
     * @return JsonResponse
     * @throws Exception
     */
    public function getDownLoadTaskList(Request $request) {
        $pageNum = $request->getParam('pagenum/d', 1);
        $pageLimit = $request->getParam('pageLimit/d', 10);

        $search = [
            'creator' => $this->getLoginId(),
            'status' => $request->getParam('status'),
            'attachname' => $request->getParam('attachname'),
            'templateid' => $request->getParam('templateid'),
            'createdatebegin' => $request->getParam('datestart'),
            'createdateend' => $request->getParam('dateend')
        ];
        $myResumeModel = new MyResumeModel();
        list($pageNum, $rowFrom, $rowTo) = $myResumeModel->paginationParameters($pageNum, $pageLimit);
        $resultBody = [];
        $count = $myResumeModel->getDownLoadTaskCount($search);
        $resultBody['totalCount'] = intval($count);
        //加入当前查询页码
        $resultBody['pagenum'] = $pageNum;
        $field = "id,creator,attachname,filepath,templateid,status,totalcount,processedcount,createdate,updatedate,startdate,enddate,extraparams";
        $myTaskList = $myResumeModel->getDownLoadTask($field, $search, $rowFrom, $rowTo);


        if (empty($myTaskList)) {
            $resultBody['status'] = false;
            $resultBody['message'] = '未查到对应记录';
            return $this->json($resultBody);
        }

        $resultBody['status'] = true;
        $resultBody['message'] = '查询成功';

        $dictStatus = $myResumeModel->DownLoadStatus();
        $dictTemplate = $myResumeModel->DictExportTemplate();
        foreach ($myTaskList as $key => &$item) {
            if ($item['startdate'] == "0000-00-00 00:00:00") {
                $item['startdate'] = '';
            }
            if ($item['enddate'] == "0000-00-00 00:00:00") {
                $item['enddate'] = '';
            }

            $item['resumeids'] = '';

            $paramText = '';
            if (!empty($item['extraparams'])) {
                $extraParamArr = @unserialize($item['extraparams']);
                if (!empty($extraParamArr) && is_array($extraParamArr)) {
                    if (isset($extraParamArr['caseresumeids']) && isset($extraParamArr['projectid']) && strlen($extraParamArr['caseresumeids']) > 0) {
                        $caseResumeModel = new CaseResumeModel();
                        $idArr = explode(",", $extraParamArr['caseresumeids']);
                        //获取客户id以获取分库信息
                        $sql = 'select subid from Project where projectid=?';
                        $result = Db::selectOne($sql, [$extraParamArr['projectid']]);

                        if (!empty($result['subid'])) {
                            $dbIndex = DbIndex::getDbIndex($result['subid']);
                            $resultList = $caseResumeModel->getListByIds($idArr, $dbIndex['dbid'], $dbIndex['tableid'], 'id,resumeid,caseid');
                            if (is_array($resultList) && count($resultList) > 0) {
                                foreach ($resultList as $resultItem) {
                                    $item['resumeids'] .= $resultItem['resumeid'] . ',';
                                }
                                $item['resumeids'] = trim($item['resumeids'], ',');
                            }
                        }
                    } else if (isset($extraParamArr['resumeids']) && isset($extraParamArr['resumeids']) > 0) {
                        $item['resumeids'] = $extraParamArr['resumeids'];
                    }

                    if (isset($extraParamArr['param_cname']) && $extraParamArr['param_cname'] == '1') {
                        $paramText .= '姓名,';
                    }
                    if (isset($extraParamArr['param_phone']) && $extraParamArr['param_phone'] == '1') {
                        $paramText .= '联系方式,';
                    }
                    if (isset($extraParamArr['param_expectsalary']) && $extraParamArr['param_expectsalary'] == '1') {
                        $paramText .= '期望薪资,';
                    }
                    if (isset($extraParamArr['param_salary']) && $extraParamArr['param_salary'] == '1') {
                        $paramText .= '目前薪资,';
                    }
                    if (isset($extraParamArr['company']) && $extraParamArr['company'] == '1') {
                        $paramText .= '最近公司,';
                    }
                    $paramText = trim($paramText, ',');
                }
            }
            $item['param_text'] = $paramText;
            $item['status_name'] = isset($dictStatus[$item['status']]) ? $dictStatus[$item['status']] : "";
            $item['templatename'] = isset($dictTemplate[$item['templateid']]) ? $dictTemplate[$item['templateid']] : '模板ID：' . $item['templateid'] . "不存在";

            unset($item['extraparam']);
        }

        $resultBody['taskList'] = $myTaskList;
        return $this->json($resultBody);
    }


    /*
     * 获取下载任务的简历附件
     */
    public function getDownLoadAttach(Request $request) {
        $myResumeModel = new MyResumeModel();
        $search = [
            'creator' => $this->getLoginId(),
            'id' => $request->getParam('id')
        ];
        $field = "creator,attachname,filepath,status,createdate,updatedate,startdate,enddate,extraparams";
        $myTaskList = $myResumeModel->getDownLoadTask($field, $search);

        if (empty($myTaskList)) {
            $resultBody['status'] = false;
            $resultBody['message'] = '未查到对应记录';
            return $this->json($resultBody);
        }

        $filePath = FILESERVER . '/' . $myTaskList[0]['filepath'];
        return response()->download($filePath, $myTaskList[0]['attachname']);
    }

    /*
     * 新建下载任务
     */
    public function createDownLoadTask(Request $request) {
        $threshold = 10;    //config('app.file_export.threshold', 10);

        $taskInfo['creator'] = $this->getLoginId();
        $taskInfo['templateid'] = $request->getParam('templateid');

        $idName = 'resumeids';
        $taskInfo[$idName] = $request->getParam($idName);
        if (empty($taskInfo[$idName])) {
            $idName = 'caseresumeids';
            $taskInfo[$idName] = $request->getParam($idName);
        }

        if (empty($taskInfo[$idName])) {
            return $this->json([
                'status' => false,
                'message' => '导出任务简历ID不可为空'
            ]);
        }

        $tmpArr = explode(",", $taskInfo[$idName]);
        $tmpArr = array_filter($tmpArr);
        if (empty($tmpArr)) {
            return $this->json([
                'status' => false,
                'message' => '导出任务简历ID不可为空'
            ]);
        }

        $myResumeModel = new MyResumeModel();
        $dictTemplate = $myResumeModel->DictExportTemplate();

        if (empty($taskInfo['templateid']) || !isset($dictTemplate[$taskInfo['templateid']])) {
            return $this->json([
                'status' => false,
                'message' => '请选择导出模板'
            ]);
        }

        $taskInfo[$idName] = implode(",", $tmpArr);
        $taskInfo['totalcount'] = count($tmpArr);
        $extraParam = array($idName => $taskInfo[$idName]);

        $extraParam['param_cname'] = $request->getParam('cname', '0');
        $extraParam['param_phone'] = $request->getParam('phone', '0');
        $extraParam['param_expectsalary'] = $request->getParam('expectsalary', '0');
        $extraParam['param_salary'] = $request->getParam('salary', '0');
        $extraParam['company'] = $request->getParam('company', '0');
        $extraParam['projectid'] = $request->getParam('projectid', '');
        $taskInfo['extraparam'] = serialize($extraParam);

        $taskId = $myResumeModel->createDownLoadTask($taskInfo, $taskInfo['totalcount'] <= $threshold ? '05' : '01');
        if ($taskId < 1) {
            return $this->json([
                'status' => false,
                'message' => '未知错误'
            ]);
        }
        if ($taskInfo['totalcount'] > $threshold) {
            return $this->json([
                'status' => true,
                'message' => '导出成功，请在 “简历库=>导出简历管理” 中查看导出进度！',
                'id' => $taskId,
                'finished' => false,
            ]);
        }

        $pos = [];
        $exportHelper = new DocxExportHelper('php://memory', $pos);
        $result = $exportHelper->export($taskId, $taskInfo['templateid'], $extraParam, $taskInfo['creator']);
        if (empty($result['relativepathname'])) {
            return $this->json([
                'status' => false,
                'message' => '导出失败'
            ]);
        }
        return $this->json([
            'status' => true,
            'message' => '导出成功！',
            'id' => $taskId,
            'finished' => true,
        ]);
    }

    //下载简历批量导入模板
    public function downloadTmpl() {
        $caseTmpl = config('app.import_tempalte');
        return response()->download($caseTmpl, '简历批量导入模板.xlsx');
    }

    /**
     * 获取任务列表
     * @param Request $request
     * @return JsonResponse
     * @throws Exception
     */
    public function getTaskList(Request $request) {
        $pageNum = $request->getParam('pagenum/d', 1);
        $pageLimit = $request->getParam('pageLimit/d', 10);

        $search = [
            'creator' => $this->getLoginId(),
            'attachname' => $request->getParam('attachname'),
            'source' => $request->getParam('source'),
            'status' => $request->getParam('status'),
            'createdatebegin' => $request->getParam('datestart'),
            'createdateend' => $request->getParam('dateend')
        ];
        $myResumeModel = new MyResumeModel();
        list($pageNum, $rowFrom, $rowTo) = $myResumeModel->paginationParameters($pageNum, $pageLimit);
        $resultBody = [];
        $count = $myResumeModel->getMyTaskCount($search);
        $resultBody['totalCount'] = intval($count);
        //加入当前查询页码
        $resultBody['pagenum'] = $pageNum;
        $field = "id,creator,attachname,filepath,source,status,totalcount,analysisedcount,createdate,updatedate,startdate,enddate,extraparam";
        $myTaskList = $myResumeModel->getMyTask($field, $search, $rowFrom, $rowTo);

        if (empty($myTaskList)) {
            $resultBody['status'] = false;
            $resultBody['message'] = '未查到对应记录';
            return $this->json($resultBody);
        }

        $resultBody['status'] = true;
        $resultBody['message'] = '查询成功';

        $dictSource = $myResumeModel->DictSource();
        $dictStatus = $myResumeModel->DictStatus();

        foreach ($myTaskList as $key => &$item) {
            if ($item['startdate'] == "0000-00-00 00:00:00") {
                $item['startdate'] = '';
            }
            if ($item['enddate'] == "0000-00-00 00:00:00") {
                $item['enddate'] = '';
            }

            $item['caseid'] = '';
            if (!empty($item['extraparam'])) {
                $extraParamArr = @unserialize($item['extraparam']);
                if (!empty($extraParamArr) && is_array($extraParamArr) && isset($extraParamArr['caseid']) && isset($extraParamArr['caseid']) > 0) {
                    $item['caseid'] = $extraParamArr['caseid'];
                }
            }
            $item['source_name'] = isset($dictSource[$item['source']]) ? $dictSource[$item['source']] : '';
            $item['status_name'] = isset($dictStatus[$item['status']]) ? $dictStatus[$item['status']] : '';
            unset($item['extraparam']);
        }

        $resultBody['taskList'] = $myTaskList;
        return $this->json($resultBody);
    }

    /*
     * 获取上传任务的简历附件
     */
    public function getTaskAttach(Request $request) {
        $myResumeModel = new MyResumeModel();
        $search = [
            'creator' => $this->getLoginId(),
            'id' => $request->getParam('id')
        ];
        $field = "creator,attachname,filepath,source,status,createdate,updatedate,startdate,enddate,extraparam";
        $myTaskList = $myResumeModel->getMyTask($field, $search);

        if (empty($myTaskList)) {
            $resultBody['status'] = false;
            $resultBody['message'] = '未查到对应记录';
            return $this->json($resultBody);
        }

        $filePath = FILESERVER . '/' . $myTaskList[0]['filepath'];
        return response()->download($filePath, $myTaskList[0]['attachname']);
    }

    /*
     * 获取对应简历的简历附件
     */
    public function getResumeBaseAttach(Request $request) {
        //MyResume/getTaskAttach?id=10
        $myResumeModel = new MyResumeModel();
        $search = [
            'creator' => $this->getLoginId(),
            'taskid' => $request->getParam('taskid'),
            'resumeid' => $request->getParam('resumeid')
        ];
        $attach = $myResumeModel->getResumeBaseAttach($search);
        if (empty($attach)) {
            $resultBody['status'] = false;
            $resultBody['message'] = '未查到对应记录';
            return $this->json($resultBody);
        }
        $filePath = FILESERVER . '/' . $attach[0]['filepath'];
        return response()->download($filePath, $attach[0]['attachname']);
    }

    /*
     * 上传简历
     */
    public function uploadResume(Request $request) {
        $validateRule = [
            'file|附件' => [
                'required',
                'minSize' => 0,
                'maxSize' => 1024 * 1024 * 5,
            ]
        ];

        $file = $request->getFile('file');
        $attachPostfix = strtolower(substr(strrchr($file->getClientOriginalName(), '.'), 1));
        $postfixArr = array("doc", "docx", "zip", "xls", "xlsx", "pdf", "txt",'html');
        if (!in_array($attachPostfix, $postfixArr)) {
            return $this->json([
                'status' => false,
                'message' => '文件类型' . $attachPostfix . '暂不支持',
            ]);
        }

        $validate = new Validator($validateRule);
        $result = $validate->validate(['file' => $file]);
        if (!$result) {
            return $this->json([
                'status' => false,
                'message' => empty($file->fileName) ? '请上传5M以内的文件' : '文件类型校验失败：' . current($validate->getErrors()),
            ]);
        }

        $directory = config('app.file_upload.directory');
        $fileHandler = new FileHandler($file);
        $result = $fileHandler->move(true, $directory);
        if (!$result) {
            return $this->json([
                'status' => false,
                'message' => '上传未知错误',
            ]);
        }

        $attachInfo['creator'] = $this->getLoginId();
        $attachInfo['source'] = $request->getParam('source');
        $attachInfo['attachname'] = $file->getClientOriginalName();
        $attachInfo['filepath'] = $result['relativepathname'];

        $attachInfo['caseid'] = $request->getParam('caseid');
        $attachInfo['extraparam'] = '';
        if (!empty($attachInfo['caseid']) && $attachInfo['caseid'] > 0) {
            $attachInfo['extraparam'] = serialize(array('caseid' => $attachInfo['caseid']));
        }

        $myResumeModel = new MyResumeModel();

        //上传单一doc/docx文件直接解析返回
        if (config('app.resume_machine_learning.single_document_urgent', false) && in_array($attachPostfix, ['doc', 'docx', 'pdf', 'txt','html'])) {
            $taskId = $myResumeModel->uploadResume($attachInfo, '05');
            if ($taskId < 1) {
                return $this->json([
                    'status' => false,
                    'message' => '未知错误'
                ]);
            }

            $taskInfo = $attachInfo + ['id' => $taskId];
            $taskInfo['caseid'] = 0;
            if (!empty($taskInfo['extraparam'])) {
                $extraParamArr = @unserialize($taskInfo['extraparam']);
                if (!empty($extraParamArr) && is_array($extraParamArr) && isset($extraParamArr['caseid']) && isset($extraParamArr['caseid']) > 0) {
                    $taskInfo['caseid'] = $extraParamArr['caseid'];
                }
            }
            $taskInfo['delfile'] = false;
            $taskInfo['urgent'] = true;     //标识为前台调起，禁用失败重试阻塞逻辑

            $fileToResume = new FileToResume();
            try {
                $success = $fileToResume->ParsingResume($taskInfo);
            } catch (\Exception $e) {
                $success = false;
                $errMsg = $e->getMessage();
                Log::error(e_dump($e), $taskInfo, 'cmd');
            }

            $sql = 'UPDATE ResumeOCRTask SET status=?,totalcount=1,analysisedcount=?,updatedate=now(),enddate=now() WHERE id=?';
            $var = [$success ? '07' : '01', $success ? 1 : 0, $taskInfo['id']];
            Db::update($sql, $var);
            if (!$success) {
                return $this->json([
                    'status' => true,
                    'message' => 'success',
                    'id' => $taskId,
                ]);
            }

            $sql = 'select resumeid from UploadResume where taskid = ?';
            $var = [$taskInfo['id']];
            $result_resumeid = Db::selectOne($sql, $var);

            if (empty($result_resumeid) || empty($result_resumeid['resumeid'])) {
                return $this->json([
                    'status' => false,
                    'message' => ($errMsg ?? '解析失败') .
                        (config('app.resume_machine_learning.mode', 0) ? '，可至 \\\\10.100.2.126\fileserver\MachineLearning\json\raw 查看机器学习接口原始返回内容' : '')
                ]);
            }

            $resumeid = $result_resumeid['resumeid'];

            if ($success) {
                return $this->json([
                    'status' => true,
                    'message' => 'success',
                    'id' => $taskId,
                    'resumeid' => $resumeid,
                    'token' => UrlCrypt::generateToken([$resumeid]),
                ]);
            }

            return $this->json([
                'status' => false,
                'message' => '解析失败'
            ]);
        }

        $taskId = $myResumeModel->uploadResume($attachInfo);
        if ($taskId < 1) {
            return $this->json([
                'status' => false,
                'message' => '未知错误'
            ]);
        }

        return $this->json([
            'status' => true,
            'message' => 'success',
            'id' => $taskId,
        ]);
    }


    public function getUploadResume(Request $request) {
        $pageNum = $request->getParam('pagenum/d', 1);
        $pageLimit = $request->getParam('pageLimit/d', 10);
        $search = [
            'oprid' => $this->getLoginId(),
            'taskid' => $request->getParam('taskid'),
            'createdatebegin' => $request->getParam('datestart'),
            'createdateend' => $request->getParam('dateend')
        ];
        $myResumeModel = new MyResumeModel();
        list($pageNum, $rowFrom, $rowTo) = $myResumeModel->paginationParameters($pageNum, $pageLimit);
        $resultBody = [];
        $count = $myResumeModel->getUploadResumeCount($search);
        $resultBody['totalCount'] = intval($count);
        //加入当前查询页码
        $resultBody['pagenum'] = $pageNum;
        $field = "id,oprid,resumeid,createdate,taskid,status,source";
        $resumeInfo = $myResumeModel->getUploadResume($field, $search, $rowFrom, $rowTo);

        if (empty($resumeInfo)) {
            $resultBody['status'] = false;
            $resultBody['message'] = '未查到对应记录';
            return $this->json($resultBody);
        }

        $resumeIds = array();
        foreach ($resumeInfo as $key => $item) {
            $resumeIds[] = $item['resumeid'];
        }

        $resumeModel = new ResumeModel();
        $resumeModel->arrValueToKey($resumeIds);
        $resumeAllInfo = $resumeModel->getRpoResumeInfo($resumeIds);

        if (empty($resumeAllInfo)) {
            $resultBody['status'] = false;
            $resultBody['message'] = '未查到对应记录';
            return $this->json($resultBody);
        }

        $resumeALL = [];
        foreach ($resumeAllInfo as $key => $item) {
            $resumeALL[$item['resumeid']]['cname'] = $item['cname'];
            $resumeALL[$item['resumeid']]['resumestatus'] = $item['status'];
            $resumeALL[$item['resumeid']]['token'] = UrlCrypt::generateToken([$item['resumeid']]);
        }

        //简历渠道来源
        $resumePlatDict = [];
        $resumePlatConfig = config('app.global_resumeplat');
        if (is_file($resumePlatConfig)) {
            $resumePlatDict = include $resumePlatConfig;
        }

        foreach ($resumeInfo as $key => $item) {
            $item['sourcename'] = isset($resumePlatDict['rpo_' . $item['source']]) ? $resumePlatDict['rpo_' . $item['source']] : '未知类型' . $item['source'];
            if (isset($resumeALL[$item['resumeid']])) {
                $resultBody['resumeList'][] = $item + $resumeALL[$item['resumeid']];
            } else {
                $resultBody['resumeList'][] = $item;
            }
        }

        $resultBody['status'] = true;
        $resultBody['message'] = '查询成功';
        return $this->json($resultBody);
    }

    /**
     * 下载数报表
     * @param Request $request
     * @return JsonResponse
     * @throws Exception
     */
    public function getMyDownloadResume(Request $request) {
        $oprId = $this->getLoginId();
        $pageNum = $request->getParam('pagenum/d', 1);
        $pageLimit = $request->getParam('pageLimit/d', 10);
        $resumeID = $request->getParam('resumeid');
        $startDate = $request->getParam('datestart');
        $endDate = $request->getParam('dateend');


        $myResumeModel = new MyResumeModel();
        list($pageNum, $rowFrom, $rowTo) = $myResumeModel->paginationParameters($pageNum, $pageLimit);

        $count = $myResumeModel->getMyDownloadResumeCount($oprId, $resumeID, $startDate, $endDate);
        $result = $myResumeModel->getMyDownloadResume($oprId, $resumeID, $startDate, $endDate, $rowFrom, $rowTo);
        if (empty($result)) {
            $count[0]['count'] = 0;
        }

        $resultBody = [
            'status' => true,
            'message' => 'success',
            'totalCount' => intval($count[0]['count']),
            'pagenum' => $pageNum,
            'resumelist' => $result,
        ];

        return $this->json($resultBody);
    }

    /**
     * 获取我的推荐列表
     * @param Request $request
     * @return JsonResponse
     * @throws Exception
     */
    public function getMyRecommendList(Request $request) {
        $pageNum = $request->getParam('pagenum/d', 1);
        $pageLimit = $request->getParam('pageLimit/d', 10);

        $search = [
            'creator' => $this->getLoginId(),
            'caseid' => $request->getParam('caseid'),
            'status' => $request->getParam('status'),
            'subname' => $request->getParam('subname'),
            'crmsubid' => $request->getParam('crmsubid'),
            'title' => $request->getParam('title'),
            'createdatebegin' => $request->getParam('datestart'),
            'createdateend' => $request->getParam('dateend')
        ];
        $myResumeRecommendModel = new ResumeRecommend();
        list($pageNum, $rowFrom, $rowTo) = $myResumeRecommendModel->paginationParameters($pageNum, $pageLimit);
        $resultBody = [];
        $count = $myResumeRecommendModel->getMyRecommendCount($search);
        $resultBody['totalCount'] = intval($count);
        //加入当前查询页码
        $resultBody['pagenum'] = $pageNum;
        $resultBody['taskList'] = [];  //解决bug:14026
        $myTaskList = $myResumeRecommendModel->getMyRecommend('id,rr.subid,s.subname,s.crmsubid,caseid,email,title,memo,firstopentime,cc,rr.createdate,rr.updatedate,rr.status,recommender,retrydate,extraparams', $search, $rowFrom, $rowTo);

        if (empty($myTaskList)) {
            $resultBody['status'] = false;
            $resultBody['message'] = '未查到对应记录';
            return $this->json($resultBody);
        }

        $resultBody['status'] = true;
        $resultBody['message'] = '查询成功';

        $customerId = [];
        foreach ($myTaskList as $key => &$item) {
            if ($item['firstopentime'] == "0000-00-00 00:00:00") {
                $item['firstopentime'] = '';
            }
            if ($item['updatedate'] == "0000-00-00 00:00:00" || $item['updatedate'] == $item['createdate']) {
                $item['updatedate'] = '';
            }

            $showFields = [];
            if (isset($item['extraparams'])) {
                $extraParams = json_decode($item['extraparams'], true);
                if (!empty($extraParams['showFields'])) {
                    foreach ($this->showFieldsDict as $name => $text) {
                        if (!empty($extraParams['showFields'][$name]) && $extraParams['showFields'][$name] == 1)
                            $showFields[] = $text;
                    }
                }
                unset($item['extraparams']);
            }
            $item['showfields'] = implode(',', $showFields);

            $customerId[$item['subid']] = '';
            $duetime = strtotime(date("Y-m-d", time())) + 8 * 86400;
            $item['url'] = $myResumeRecommendModel->creatRecommendToken($item['subid'], $item['id'], $duetime, 'istest');
        }

        $customerModel = new Customer();
        $customerList = $customerModel->GetCustomerListByIds($customerId);
        $customerName = [];
        if (!empty($customerList)) {
            foreach ($customerList as $citem) {
                $customerName[$citem['subid']] = $citem['subname'];
            }
        }

        foreach ($myTaskList as $key => &$item) {
            if (empty($item['subid'])) {
                continue;
            }
            $item['subname'] = isset($customerName[$item['subid']]) ? $customerName[$item['subid']] : '';
        }

        $resultBody['taskList'] = $myTaskList;
        return $this->json($resultBody);
    }

    public function resendRecommendEmail(Request $request) {
        $recommendId = $request->getParam('recommendid');
        //获取推荐记录
        $recommendModel = new ResumeRecommend();
        $result = $recommendModel->resendRecommendEmail($recommendId);
        return $this->json($result);
    }
}